import requests
import pytest

from api import log
from api.api_recharge import ApiRecharge
from api.api_register_login import ApiRegisterLogin
from api.api_tender import ApiTender
from tools import html_parse, common_assert, read_json


class TestTennder:
    #初始化
    @pytest.fixture(autouse=True)
    def setup(self):
        #获取session
        self.session = requests.session()
        #获取ApiTender对象
        self.api =ApiTender(self.session)
        #登录
        r =ApiRegisterLogin(self.session).api_login()
    #结束
    def teardown(self):
        self.session.close()
    #投资接口测试
    @pytest.mark.parametrize("amount,expect_text",read_json("tender.json","tender"))
    def test01_tennder(self,amount,expect_text):
        try:
            result = self.api.api_tender(amount)
            log.info("投资接口的执行结果为{}".format(result.json()))
            #三方投资
            if expect_text == "OK":
                data = html_parse(result)
                result = self.session.post(url=data[0], data=data[1])
                log.info("三方接口的执行结果是{}".format(result.text))
            common_assert(result,text=expect_text)
            log.info("三方接口断言通过")
        except Exception as e:
            log.error(e)
